<!DOCTYPE html>
<html lang="en">
<head>
  <title>array events</title>
  <meta charset="utf-8"/>
  <script src="../../dist/jsoneditor.js"></script>
</head>
<body>

<h1>Test</h1>
<label for="debug">Value</label>
<textarea id="debug" class="debug" cols="30" rows="10"></textarea>
<button class='get-value'>Get Value</button>

<label for="action1">Action1</label>
<textarea id="action1" cols="30" rows="5"></textarea>

<label for="action2">Action2</label>
<textarea id="action2" cols="30" rows="5"></textarea>

<div class='container'></div>

<script>
  const container = document.querySelector('.container');
  const debug = document.querySelector('.debug');
  const action1 = document.querySelector('#action1');
  const action2 = document.querySelector('#action2');
  const schema = {
    "type": "array",
    "title": "Strings",
    "items": {
      "type": "string",
      "title": "String"
    }
  };

  const editor = new JSONEditor(container, {
    schema: schema,
    enable_array_copy: true
  });
  editor.promise.then(() => {
    document.querySelector('.get-value').addEventListener('click', function () {
      debug.value = JSON.stringify(editor.getValue());
    });

    editor.setValue(["A", "B"]);

    editor.on('copyRow', function () {
      action2.value = 'copyRow'
      console.log('copyRow');
    });

    editor.on('moveRow', function () {
      action1.value = 'moveRow';
      console.log('moveRow');
    });

    editor.on('addRow', function () {
      action1.value = 'addRow'
      console.log('addRow')
    });

    editor.on('deleteRow', function () {
      action1.value = 'deleteRow'
      console.log('deleteRow')
    });

    editor.on('deleteAllRows', function () {
      action1.value = 'deleteAllRows'
      console.log('deleteAllRows')
    });
  })
</script>
</body>
</html>
